/*
 * @Descripttion: 
 * @version: 
 * @Author: TT
 * @Date: 2023-10-28 15:05:41
 * @LastEditors: TT-hzy
 * @LastEditTime: 2024-07-26 15:25:28
 */

import 'package:flutter/material.dart';
import 'package:hzy_project_template/base_ui_config/base_ui_config_index.dart';
import 'package:hzy_project_template/commpontents/commpontents_index.dart';
import 'package:hzy_project_template/config/config_index.dart';
import 'package:hzy_project_template/models/models_index.dart';
import 'package:hzy_project_template/pages/root/root_v.dart';
import 'package:hzy_project_template/utils/utils_index.dart';

import '../../../commpontents/normal_like_empty_widget.dart';
import '../models/tu_chong_model.dart';
import '../tools/tu_chong_utils.dart';
import '../vm/tu_chong_state.dart';
import '../vm/tu_chong_vm.dart';
import '../widgets/example_tu_item_widget.dart';

class TuChongCollectListV extends CommonGetXlistV<TuChongCollectListC> {
  TuChongCollectListV({Key? key}) : super(key: key);
  @override
  TuChongCollectListC get controller => Get.put(TuChongCollectListC());

  @override
  Widget createListView(
    BuildContext context,
  ) {
    Widget body = GetBuilder<TuChongCollectListC>(
      builder: (controller) {
        Widget bt = ListView.builder(
          itemBuilder: (context, index) {
            return ExampleTuItemlessV(
              tuChongItem: controller.state.collecList[index],
              tapOneKey: (tuChongItem) {
                controller.tapOneKey(
                  tuChongItem: tuChongItem,
                );
              },
              type: 1,
            );
          },
          itemCount: controller.state.collecList.length,
        );

        return bt;
      },
    );
    return body;
  }

  @override
  Widget? createEmptyWidget() {
    Widget body = NormalLikeEmptyWidget(
      tapCall: () {
        controller.tapEmpty();
      },
    );
    body = SizedBox(
      width: SizeMacro.screenWidth,
      height: SizeMacro.screenHeight,
      child: body,
    );
    return body;
  }
}

class TuChongCollectListC extends CommonGetXListController {
  // --------- 属性 --------- //
  TuChongVM tuChongVM = TuChongVM();
  TuChongState state = TuChongState();
  // --------- 生命周期  --------- //
  @override
  configDefault() {
    super.configDefault();
    placeBtnMsg = NoteLauncIdConfig.toDiscover.tr;
    isShowAppBar = false;
    getNetWorkData(type: 3);
  }

  @override
  getNetWorkData({
    int? type,
    Map<String, dynamic>? info,
  }) async {
    state = await tuChongVM.configCollectListData();

    pageState.value = endRefresh(
      type: type ?? 1,
      state: state.pageState,
    );
    update();
  }

  // --------- 触发事件  --------- //
  // 点击缺省页触发事件
  @override
  tapPlaceHoldWidgetMethod({
    required CommonPlaceHoldType placeHoldType,
  }) {
    Get.put(RootC()).tapTabItem(index: 0);
  }

  /// 点击空数据 按钮
  tapEmpty() {
    Get.put(RootC()).tapTabItem(index: 0);
  }

  tapOneKey({
    required TuChongItem tuChongItem,
  }) {
    List<ImageNormalModel> imagelist = TuChongUtils.configDetailImageModelList(
      tuChongItem: tuChongItem,
      width: SizeMacro.screenWidth,
    );
    showToolTop(
      popType: 1,
      type: 1,
      list: imagelist,
      tapCall: (index) {
        if (index != 0) {
          configTapSelectImageTool(
            type: index,
            list: imagelist,
          );
        } else {
          tuChongVM.configDelectCollect(
            tuChongItem: tuChongItem,
          );
        }
      },
    );
  }
}
